﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SqlMiM.Common.ViewModel;
using System.Collections.ObjectModel;
using SqlMiM.SqlServer.Model;
using MvvmFoundation.Wpf;

namespace SqlMiM.SqlServer.ViewModel
{
    public class FileGroupView : ObservableObject
    {

        private FileGroup fileGroup;

        public FileGroup FileGroup
        {
            get { 
                return fileGroup; 
            }
            set { 
                fileGroup = value;
                this.RaisePropertyChanged("FileGroup");
            }
        }

        private ObservableCollection<Size> allSizes;


        public ObservableCollection<Size> AllSizes
        {
            get
            {
                if (allSizes == null)
                    allSizes = new ObservableCollection<Size>();

                allSizes.Add(new Size() { Name = "SpaceUsed", Value = this.fileGroup.SpaceUsed });
                allSizes.Add(new Size() { Name = "FreeSpace", Value = this.fileGroup.FreeSpace });

                return allSizes;
            }
       }

    
        public Single PercentFreeSpace
        {
            get 
            {
                if (this.fileGroup.CurrentSize == 0)
                    return 0;

                return (float)((this.fileGroup.FreeSpace * 100) / this.fileGroup.CurrentSize);
            }
            
        }

        public String PercentFreeSpaceText
        {
            get
            {
                return String.Format("{0} %", this.PercentFreeSpace.ToString());
            }
        }

        public FileGroupView()
        {

        }
        public FileGroupView(FileGroup fg)
        {
            this.FileGroup = fg;
        }
    }
}
